class Login{
    constructor(){
        this.loginBtn = $("#logoinBtn");
        this.userElement = $("#user");
        this.passwordElement = $("#password");
        this.tipsEle = $("#tips");
    }
    addEvent(){
        var that = this;
        this.loginBtn.on("click",function(){
            that.user = that.userElement.prop("value");
            that.password = that.passwordElement.prop("value");
            that.ajax();
        });
    }
    ajax(){
        this.tipsEle.css({
            display:"none",
        });
        var that =this;
        var p1 = pAjax({
            type:"get",
            url:"http://localhost/XMYP/src/php/login.php",
            data:{
                user:that.user,
                password:that.password,
            }
        }).then(function(res){
            if(JSON.parse(res).code==1){
                that.tipsEle.css({
                    display:"block",
                });
                that.tipsEle.text(JSON.parse(res).errMsg);
            }else if(JSON.parse(res).code==2){
                that.tipsEle.css({
                    display:"block",
                });
                var str = JSON.parse(res).data;
                sessionStorage.setItem("data",JSON.stringify(str));
                window.location.href=`http://localhost/XMYP/src/index.html?user=${str[0].user}`;
            }
        });
        
    }
    dump(){
        $(".mainbox_bOther_tl").on("click",function(){
            window.location.href='./register.html';
        });
        $(".mainbox_bOther_tr").on("click",function(){
            window.location.href='./register.html';
        });
    }
}

var login = new Login();
login.addEvent();
login.dump();